** This dofile makes the results related to import growth

/*
Table A2: Import Growth of US Importers during 2004-2007
*/

** For Table A2
use "${output_data}matched_exp_imp_hs6_junedecember_maquila_restrict.dta", replace
collapse (sum) value_exporter_importer, by(newclid2 hs6 year)
keep if year==2004 | year==2007
rename value value
reshape wide value, i(newclid2 hs6) j(year)
drop if value2004==.
drop if value2007==.
gen dlimport=log(value2007)-log(value2004)
drop if dlimport==.
keep newclid hs6 dlimport
save "${temp_data}dlimport.dta", replace

use "${output_data}US_for_analysis_04_07_hs6_restrict.dta", clear
* Set iq_mex_bind80 as a Binding measure
rename iq_mex_bind80 Binding
merge m:1 hs6_importer_id using "${output_data}importer_rank.dta" 
keep if _merge==3
drop _merge
gen rrank_own=(importer_own_rank-1)/(n_importer_2004-1)
gen rrank_own_Binding=rrank_own*Binding
gen upgrade_Binding=i_e_mv_rank_d0704*Binding
gen upgrade=i_e_mv_rank_d0704
merge 1:1 hs6 newclid2 using "${temp_data}dlimport.dta"
keep if _merge==3
keep if upgrade!=.
label var dlimport "ImportGrowrh"

eststo clear
eststo: xi:reg dlimport Binding rrank_own i.hs2, cluster(hs6)
eststo: xi:reg dlimport Binding rrank_own rrank_own_Binding i.hs2, cluster(hs6)
eststo: xi:reg dlimport Binding i.hs2, cluster(hs6)
eststo: xi:reg dlimport Binding upgrade upgrade_Binding i.hs2, cluster(hs6)

esttab using "${output}import_growth/import_growth.tex", replace label nonumbers coeflabels(Binding "Binding" rrank_own "OwnRank" rrank_own_Binding "OwnRank \times Binding" upgrade "Up^{US}_{igp}" upgrade_Binding "Up^{US}_{igp} \times Binding" _cons "cons") indicate("Sector FE (HS2)=_Ihs2*") starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3)))  stats(r2 N, fmt(%9.3f %9.0f) labels(R-Squared Obs.)) posthead( &\multicolumn{4}{c}{$\Delta$ ln Import_{igs}}\\ \hline &(1)&(2)&(3)&(4)\\  \hline) nomtitles
